package com.example.demo.servlet;

import com.example.demo.dao.Admindao;
import com.example.demo.dao.UserDao;
import com.example.demo.entity.AdminVo;
import com.example.demo.entity.UserVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String repassword = req.getParameter("repassword");
        String telephone = req.getParameter("telephone");
        String gender = req.getParameter("gender");
        UserVo userVo = new UserVo();
        try {
            if(password.equals(repassword)){
                userVo.setUserName(username);
                userVo.setPassword(password);
                userVo.setTelephone(telephone);
                userVo.setGender(gender);
                new UserDao().saveUser(userVo);
                System.out.println(userVo);
                req.getRequestDispatcher("/getregister").forward(req, resp); ;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
